import cv2
import matplotlib.pyplot as plt
import numpy as np

plt.rcParams["font.family"] = ["SimHei", "WenQuanYi Micro Hei", "Heiti TC", "sans-serif"] #防止中文显示不了
img = cv2.imread("1.jpg")
rows,cols = img.shape[:2]

# #绝对尺寸
# res =  cv2.resize(img,(2 * rows,2* cols),interpolation=cv2.INTER_NEAREST)
# res1 =  cv2.resize(img,None,fx=0.5,fy=0.5,interpolation=cv2.INTER_NEAREST)
#
# #使用opencv显示图像（不推荐）
# cv2.imshow("orignal",img)
# cv2.imshow("enlarge",res)
# cv2.imshow("shrink",res1)
#
# cv2.waitKey(0)
#
# fig,axes = plt.subplots(nrows=1,ncols=3)
#
# axes[0].imshow(img[:,:,::-1])
# axes[0].set_title("原图")
# axes[1].imshow(res[:,:,::-1])
# axes[1].set_title("绝对尺寸（放大）")
# axes[2].imshow(res1[:,:,::-1])
# axes[2].set_title("相当尺寸（缩小）")
#
# plt.show()

M = np.float32([[1,0,100],[0,1,50]])

dst = cv2.warpAffine(img,M,(rows,cols))

fig,axes = plt.subplots(nrows=1,ncols=2)

axes[0].imshow(img[:,:,::-1])
axes[0].set_title("原图")
axes[1].imshow(dst[:,:,::-1])
axes[1].set_title("平移后结果")

plt.show()
